package com.zyl.blog.CogniSphere.controller;

import com.zyl.blog.CogniSphere.service.SparkAiHttpService;
import com.zyl.blog.common.domain.ai.dto.TableMeta;
import com.zyl.blog.common.response.Result;
import com.zyl.blog.common.utils.Extreme.LogUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version v1.0
 * @ProjectName: Personal_Blog_Server
 * @Package: com.zyl.blog.CogniSphere.controller
 * @ClassName: SqlGeneratorController
 * @Description: 智能AI控制器
 * @Author FinalFantasy
 * @Date 2025/8/15-10:48
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/ai")
public class SqlGeneratorController {

    private final SparkAiHttpService sqlService;

    /**
     * 生成创建表的SQL
     */
    @PostMapping("/sql/generate/create-table")
    public Result<String> generateCreateTableSql(
            @RequestBody TableMeta tableMeta
    ) {
        try {
            String sql = sqlService.generateCreateTableSql(tableMeta);
            return Result.ok(sql);
        } catch (Exception e) {
            LogUtil.error("生成SQL失败: [{}]", null, e);
            return Result.fail(e.toString());
        }
    }

}